17
class Solution {
    public ListString letterCombinations(String digits) {
        int len = digits.length();
        ListString ret = new ArrayList();
        if (len == 0) {
            return ret;
        }
        char[][] arr = new char[8][];
        arr[0] = abc.toCharArray();
        arr[1] = def.toCharArray();
        arr[2] = ghi.toCharArray();
        arr[3] = jkl.toCharArray();
        arr[4] = mno.toCharArray();
        arr[5] = pqrs.toCharArray();
        arr[6] = tuv.toCharArray();
        arr[7] = wxyz.toCharArray();
        fun(ret, new StringBuilder(), 0, arr, digits);
        return ret;
    }

    public void fun(ListString ret, StringBuilder str, int index, char[][] arr, String digits) {
        if (index == digits.length()) {
            ret.add(str.toString());
            return;
        }
        int a = digits.charAt(index) - '0';
        for (int i = 0; i  arr[a-2].length; i++) {
            str.append(arr[a-2][i]);
            fun(ret, str, index+1, arr, digits);
            str.deleteCharAt(index);
        }
    }
}
给定两个数，求这两个数的最大公约数

例如：

输入：20 40

输出：20
import java.util.Scanner;

public class Main{
    public static void main (String[] arr){
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        while(true){
            if (n % m == 0){
                System.out.println("最大公约数为"+m);
                break;
            }
            int tmp = n % m;
            n = m;
            m = tmp;
        }
    }
}